package com.rgs.nginx.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @Classname InvestorLogAspect
 * @Description TODO
 * @Date 2025/2/13 15:32
 * @Created by rgs
 */

@Aspect
@Component
@Slf4j
public class InvestorLogAspect {

    @Pointcut("execution(* com.rgs.nginx.controller..*.*(..))")
    public void controllerAspect() {}

    // 异常通知：方法抛出异常时执行
    @AfterThrowing(pointcut = "controllerAspect()", throwing = "exception")
    public void afterThrowing(JoinPoint joinPoint,Exception exception) {
        Object[] args = joinPoint.getArgs();
        // 方法报错了，就执行这个
        System.out.println("异常通知：执行成功，报错原因： " + exception.getMessage());
    }

    // 最终通知：方法执行结束后
    @AfterReturning(pointcut = "controllerAspect()", returning = "result")
    public void afterReturning(JoinPoint joinPoint,Object result) {

        Object[] args = joinPoint.getArgs();
        // 方法没有报错，就执行这个
        System.out.println("最终通知：执行成功，结果：" + result);
    }

}
